package com.example.qundui.learndemo.blooath;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

/**
 * Created by qundui on 2017/5/5.
 */
public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action=intent.getAction();
        Log.i("boye", action);
        if(action.equals(BluetoothDevice.ACTION_FOUND)) {
            BluetoothDevice device=intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);    //获取当前扫描到的设备

            if(device.getBondState()==BluetoothDevice.BOND_BONDED) {
                //显示已配对设备

                Log.i("gsc",device.getName()+"==>"+device.getAddress());
                Toast.makeText(context, "发现已配对设备:" + device.getName(), Toast.LENGTH_LONG).show();
            } else if(device.getBondState()!=BluetoothDevice.BOND_BONDED) {
                Log.i("gsc",
                        device.getName()+device.getAddress());
               // textView3.append("\n"+device.getName()+"==>"+device.getAddress()+"\n");
                Toast.makeText(context, "发现未配对设备:" + device.getName(), Toast.LENGTH_LONG).show();
            }
        } else if(action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)){
//            textView2.setText("搜索完成...");
            Log.i("gsc","搜索完成...");
        }

    }
}
